<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\Grade;
use App\Models\Student;

class SelectLoadDataController extends Controller
{
    public function classData(Request $request)
    {
        $major_id = $request->get('q');
        $grades = Grade::where('major_id', $major_id)->get(['id', DB::raw('class_name as text')]);

        return $grades;
    }

    public function studentDate(Request $request) {
        $grade_id = $request->get('q');
        $students = Student::where('class_id', $grade_id)->get(['id', DB::raw('name as text')]);

        return $students;
    }

    public function schoolmateDate(Request $request) {
        $sutdent_id = $request->get('q');
        $sudent = Student::where('id',$sutdent_id)->first();
        $grade_id = $sudent->class_id;
        $students = Student::where('class_id', $grade_id)->where('id','<>',$sutdent_id)->get(['id', DB::raw('name as text')]);

        return $students;
    }
}
